"""
@Project:workflow_python
@File:serializers.py
@Author:袁浩天
@Date:14:29
"""
from .models import *

from rest_framework import serializers
from rest_framework.validators import ValidationError

import re


# 模板类型 template_name type
class TemplateSer(serializers.ModelSerializer):
    class Meta:
        model = Template
        fields = "__all__"

    def validate(self, attrs):
        template_name = attrs.get("template_name")
        if not re.findall(r"[\u4e00-\u9fa5]{1,9}",template_name):
            raise ValidationError(f'{template_name}名称由2到9为汉字组成')
        return attrs


# 请假类型type_name  type
class LeaveTypeSer(serializers.ModelSerializer):
    class Meta:
        model = Leave_Type
        fields = "__all__"

    def validate(self, attrs):
        type_name = attrs.get("type_name")
        if not re.findall(r"[\u4e00-\u9fa5]{1,9}",type_name):
            raise ValidationError(f'{type_name}名称由2到9为汉字组成')
        return attrs


# 请假模板cause begin_time end_time end_time type
class LeaveSer(serializers.ModelSerializer):
    class Meta:
        model = Leave
        fields = "__all__"


# 借款模板begin_time cause money type
class MoneySer(serializers.ModelSerializer):
    class Meta:
        model = Money
        fields = "__all__"


# 出差模板cause begin_time end_time address peer type
class TravelSer(serializers.ModelSerializer):
    class Meta:
        model = Travel
        fields = "__all__"


# 转正模板 begin_time cause type
class FormalSer(serializers.ModelSerializer):
    class Meta:
        model = Formal
        fields = "__all__"


# 用车模板 begin_time end_time start end vehicle plate type begin_time cause type
class CarSer(serializers.ModelSerializer):
    class Meta:
        model = Car
        fields = "__all__"


# 报销模板voucher type  cause money
class ExpenseSer(serializers.ModelSerializer):
    class Meta:
        model = Expense
        fields = "__all__"


class VehicleSer(serializers.ModelSerializer):
    class Meta:
        model = Vehicle
        fields = "__all__"


class PlateSer(serializers.ModelSerializer):
    class Meta:
        model = Plate
        fields = "__all__"

